package leetcode.editor.cn;

import java.util.ArrayList;
import java.util.List;

/**
 * 子集
 * @author qulq
 * @date 2024-07-07 21:55:57
 */
public class T78_Subsets{
	 public static void main(String[] args) {
	 	 //测试代码
	 	 Solution solution = new T78_Subsets().new Solution();
	 }
	 
//力扣代码
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {

	List<List<Integer>> ans = new ArrayList<>();
	List<Integer> path = new ArrayList<>();

	public List<List<Integer>> subsets(int[] nums) {
		backtracking(nums, 0);
		return ans;
    }

	private void backtracking(int[] nums, int start) {

		ans.add(new ArrayList<>(path));

		// 终⽌条件可以不加，因为start >= nums.length，本层for循环本来也结束了。
//		if (start >= nums.length) {
//			return;
//		}

		for (int i = start; i < nums.length; i++) {
			path.add(nums[i]);
			backtracking(nums, i + 1);
			path.remove(path.size() - 1);
		}
	}
}
//leetcode submit region end(Prohibit modification and deletion)

}